#include "DataProcessing.h"


DataProcessing::DataProcessing()
{
  condition = 0;
  index = 0;
  total = 0;
  preData = 0;
  nowData = 0;
  preTime = 0;
  nowTime = 0;
  for(int j=0; j<numReading; j++)
  {
    readings[j] = 0;
  }
}

DataProcessing::~DataProcessing()
{
}

void DataProcessing::smoothData(int t)
{
  total = total - readings[index];
  readings[index] = t;
  total +=readings[index];
  index++;

  if (index>=numReading)
    index = 0;
  nowTime = millis();
  nowData = total / numReading;
} 

int DataProcessing::getNowData()
{
  return nowData;
}

int DataProcessing::getPreData()
{
  return preData;
}

boolean DataProcessing::getCondition()
{
  return condition;
}

void DataProcessing::setCondition(boolean t)
{
  condition = t;
}

boolean DataProcessing::compareTime(int t)
{
  if(nowTime-preTime>t)
    return true;
  else
    return false;
}

boolean DataProcessing::compareData(int t)
{
  if(nowData-preData>t)
    return true;
  else
    return false;
}

void DataProcessing::setPreTime()
{
  preTime = nowTime;
}

void DataProcessing::setPreData()
{
  preData = nowData;
}
